package com.atguigu.scw.manager.controller.permission;

import com.atguigu.scw.manager.bean.TPermission;
import com.atguigu.scw.manager.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/permission/menu")
@Controller
public class MenuController {

    @Autowired
    PermissionService permissionService;

    @RequestMapping("/list")
    public String menuList() {
        return "manager/permission/menu";
    }

    @ResponseBody
    @RequestMapping("/getAllMenu")
    public List<TPermission> getAllMenu() {
        return permissionService.getPermissions();
    }

    @ResponseBody
    @RequestMapping("/addMenu")
    public String addMenu(TPermission permission) {
        permissionService.savePermission(permission);
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/getMenuById")
    public TPermission getMenuById(Integer id) {
        return permissionService.getMenuById(id);
    }

    @ResponseBody
    @RequestMapping("/updateMenu")
    public String updateMenu(TPermission permission) {
        permissionService.updateMenu(permission);
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/deleteMenuById")
    public String deleteMenuById(Integer id) {
        permissionService.deleteMenuById(id);
        return "ok";
    }
}